/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GerenciadorAlocacao.java
 *
 * Created on 28/05/2011, 11:47:09
 */

package gui;

import fachadas.*;
import entidades.*;
import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
/**
 *
 * @author Thiago
 */
public class GerenciadorAlocacao extends javax.swing.JFrame {

    private UserInterfaceFacade gerAlocacoes;
    private ArrayList<Evento> eventos;
    private ArrayList<Sala> salas;
    private DefaultListModel modeloSala;
    private DefaultListModel modeloEvento;

    /** Creates new form GerenciadorAlocacao */
    public GerenciadorAlocacao() {
    	
        gerAlocacoes = new UserInterfaceFacade();
        salvar();
        
        eventos = new ArrayList<Evento>();
        salas = new ArrayList<Sala>();
        modeloSala = new DefaultListModel();
        modeloEvento = new DefaultListModel();
        
        initComponents();
        setLocationRelativeTo(null);
        setTitle("Gerenciador de Alocacao");

        atualizaEventosDoGerenciador();//Busca os eventos do sistema pro atributo eventos
        atualizaSalasDoGerenciador();//Busca as salas do sistema pro atributo salas
        atualizaDados();//Atualiza os dados das salas e eventos na interface
        atualiza();//Atualiza dados relacionados a interface
    }

    private void salvar() {
    	gerAlocacoes.menuSair();
	}

	/** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton_Voltar = new javax.swing.JButton();
        jButton_ZerarSistema = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel_Salas = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList_Salas = new javax.swing.JList();
        jButton_Alocar = new javax.swing.JButton();
        jLabel_Salas = new javax.swing.JLabel();
        jPanel_Eventos = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jList_Eventos = new javax.swing.JList();
        jLabel_Eventos = new javax.swing.JLabel();
        jButton_Desalocar = new javax.swing.JButton();
        jLabel_Msg_EvAtual = new javax.swing.JLabel();
        jPanel_VerificaDados = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel_SalasExistentes = new javax.swing.JLabel();
        jLabel_SalasAlocadas = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel_EventosExistentes = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel_EventosAlocados = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton_Voltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/backIcon.png"))); // NOI18N
        jButton_Voltar.setText("Voltar");
        jButton_Voltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_VoltarActionPerformed(evt);
            }
        });

        jButton_ZerarSistema.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/clear.png"))); // NOI18N
        jButton_ZerarSistema.setText("Zerar Sistema");
        jButton_ZerarSistema.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_ZerarSistemaActionPerformed(evt);
            }
        });

        jList_Salas.setFixedCellWidth(500);
        jList_Salas.setMaximumSize(new java.awt.Dimension(450, 300));
        jList_Salas.setMinimumSize(new java.awt.Dimension(450, 300));
        jScrollPane1.setViewportView(jList_Salas);

        jButton_Alocar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/alocar.png"))); // NOI18N
        jButton_Alocar.setText("Alocar");
        jButton_Alocar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_AlocarActionPerformed(evt);
            }
        });

        jLabel_Salas.setText("Salas");

        javax.swing.GroupLayout jPanel_SalasLayout = new javax.swing.GroupLayout(jPanel_Salas);
        jPanel_Salas.setLayout(jPanel_SalasLayout);
        jPanel_SalasLayout.setHorizontalGroup(
            jPanel_SalasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_SalasLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel_SalasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel_SalasLayout.createSequentialGroup()
                        .addComponent(jLabel_Salas)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel_SalasLayout.createSequentialGroup()
                        .addGroup(jPanel_SalasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton_Alocar, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE))
                        .addGap(40, 40, 40))))
        );
        jPanel_SalasLayout.setVerticalGroup(
            jPanel_SalasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_SalasLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel_Salas)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_Alocar, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel_Eventos.setPreferredSize(new java.awt.Dimension(299, 332));

        jList_Eventos.setFixedCellWidth(900);
        jList_Eventos.setMaximumSize(new java.awt.Dimension(450, 300));
        jList_Eventos.setMinimumSize(new java.awt.Dimension(450, 300));
        jScrollPane2.setViewportView(jList_Eventos);

        jLabel_Eventos.setText("Eventos");

        jButton_Desalocar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/desalocar.png"))); // NOI18N
        jButton_Desalocar.setText("Desalocar");
        jButton_Desalocar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_DesalocarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel_EventosLayout = new javax.swing.GroupLayout(jPanel_Eventos);
        jPanel_Eventos.setLayout(jPanel_EventosLayout);
        jPanel_EventosLayout.setHorizontalGroup(
            jPanel_EventosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel_EventosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel_EventosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton_Desalocar, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel_Eventos, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 252, Short.MAX_VALUE))
                .addGap(23, 23, 23))
        );
        jPanel_EventosLayout.setVerticalGroup(
            jPanel_EventosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_EventosLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel_Eventos)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_Desalocar, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jLabel_Msg_EvAtual.setForeground(new java.awt.Color(245, 16, 13));
        jLabel_Msg_EvAtual.setText("Obs: Eventos com * significa que estao alocados");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel_Salas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel_Eventos, javax.swing.GroupLayout.PREFERRED_SIZE, 287, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(35, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(169, Short.MAX_VALUE)
                .addComponent(jLabel_Msg_EvAtual)
                .addGap(165, 165, 165))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel_Salas, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel_Eventos, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel_Msg_EvAtual))
        );

        jTabbedPane1.addTab("Gerenciar Alocacao", jPanel1);

        jLabel1.setText("Salas Existentes:");

        jLabel2.setText("Salas Alocadas:");

        jLabel_SalasExistentes.setText("Valor");

        jLabel_SalasAlocadas.setText("Valor");

        jLabel3.setText("Eventos Existentes:");

        jLabel_EventosExistentes.setText("valor");

        jLabel4.setText("Eventos Alocados:");

        jLabel_EventosAlocados.setText("valor");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addGap(28, 28, 28)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_EventosAlocados)
                    .addComponent(jLabel_EventosExistentes)
                    .addComponent(jLabel_SalasAlocadas)
                    .addComponent(jLabel_SalasExistentes))
                .addContainerGap(398, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel_SalasExistentes))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel_SalasAlocadas))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel_EventosExistentes))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel_EventosAlocados))
                .addContainerGap(133, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel_VerificaDadosLayout = new javax.swing.GroupLayout(jPanel_VerificaDados);
        jPanel_VerificaDados.setLayout(jPanel_VerificaDadosLayout);
        jPanel_VerificaDadosLayout.setHorizontalGroup(
            jPanel_VerificaDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_VerificaDadosLayout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel_VerificaDadosLayout.setVerticalGroup(
            jPanel_VerificaDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_VerificaDadosLayout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(54, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Verificar Dados", jPanel_VerificaDados);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 657, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(jButton_ZerarSistema, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(341, 341, 341)
                        .addComponent(jButton_Voltar, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 394, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_ZerarSistema, javax.swing.GroupLayout.DEFAULT_SIZE, 37, Short.MAX_VALUE)
                    .addComponent(jButton_Voltar, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_VoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_VoltarActionPerformed
        new TelaPrincipal().setVisible(true);
        dispose();
    }//GEN-LAST:event_jButton_VoltarActionPerformed

    private void jButton_ZerarSistemaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_ZerarSistemaActionPerformed
    	gerAlocacoes.zerarSistema();
    	gerAlocacoes.zerarPersistencia();
    	salvar();
        atualizaModelos();
        atualizaSalasDoGerenciador();
        atualizaEventosDoGerenciador();
        atualizaDados();
    }//GEN-LAST:event_jButton_ZerarSistemaActionPerformed

    private void jButton_DesalocarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_DesalocarActionPerformed
        Evento evento = null;

        try{
            evento = eventos.get(jList_Eventos.getSelectedIndex());
        }catch(Exception e){
            if (jList_Eventos.isSelectionEmpty())
                JOptionPane.showMessageDialog(null,
                        "Erro ao Desalocar:\n\n"+
                        "Selecione um Evento para ser desalocado",
                        "Falha ao Desalocar Evento", JOptionPane.ERROR_MESSAGE);
            
            return;
        }

        try{
            if (evento.estaAlocado()){
                gerAlocacoes.desalocarEvento(evento.getId());
                JOptionPane.showMessageDialog(null,
                        "Evento Desalocado com Sucesso",
                        "Sucesso ao Desalocar Evento",
                        JOptionPane.INFORMATION_MESSAGE);
            }else {
                JOptionPane.showMessageDialog(null,
                        "Erro ao Desalocar Evento\n\n" +
                        "O Evento selecionado nao esta alocado",
                        "Falha ao Desalocar Evento", JOptionPane.ERROR_MESSAGE);
            }
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, e.getMessage() + "\n\n",
                    "Falha ao Desalocar", JOptionPane.ERROR_MESSAGE);
        }
        jList_Salas.clearSelection();
        atualiza();
        atualizaDados();
        salvar();
}//GEN-LAST:event_jButton_DesalocarActionPerformed

    private void jButton_AlocarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_AlocarActionPerformed

        Evento evento = null;
        Sala sala = null;

        //Caso nem sala nem evento estejam selecionados
        if (jList_Salas.isSelectionEmpty() && jList_Eventos.isSelectionEmpty()){
            JOptionPane.showMessageDialog(null, "Erro ao Executar Alocacao:\n\n"+
                    "Selecione uma Sala e um Evento para efetuar a alocacao",
                    "Falha na Alocacao", JOptionPane.ERROR_MESSAGE);
            return;
        }

        //Caso o evento nao esteja selecionado
        try{
            evento = eventos.get(jList_Eventos.getSelectedIndex());
            
        }catch(Exception e){
            if (jList_Eventos.isSelectionEmpty()){
                JOptionPane.showMessageDialog(null,
                        "Erro ao Executar Alocacao:\n\n"+
                        "Selecione um Evento para efetuar a alocacao",
                        "Falha na Alocacao", JOptionPane.ERROR_MESSAGE);
            }
            return;
        }

        //Caso a sala nao esteja selecionada
        try{
            sala = salas.get(jList_Salas.getSelectedIndex());
        }catch(Exception e){
            if (jList_Salas.isSelectionEmpty()){
                JOptionPane.showMessageDialog(null,
                        "Erro ao Executar Alocacao:\n\n"+
                        "Selecione uma Sala para efetuar a alocacao",
                        "Falha na Alocacao", JOptionPane.ERROR_MESSAGE);
            }
            return;
        }

        //Aloca um evento selecionado a uma sala selecionada
        try{
            gerAlocacoes.alocarEvento(evento.getId(), sala.getId());
            JOptionPane.showMessageDialog(null, "Alocacao efetuada com Sucesso",
                    "Sucesso na Alocacao", JOptionPane.INFORMATION_MESSAGE);

        }catch(Exception e){
            JOptionPane.showMessageDialog(null, e.getMessage() + "\n\n"
                    , "Falha na Alocacao", JOptionPane.ERROR_MESSAGE);
        }
        atualiza();
        atualizaDados();
        salvar();
}//GEN-LAST:event_jButton_AlocarActionPerformed

// Metodos responsaveis por atualizar o sistema ===============================
    private void atualiza(){
        atualizarSalas();
        atualizarEventos();
    }

    private void atualizarSalas(){
        modeloSala = new DefaultListModel();
        jList_Salas.setModel(modeloSala);

        for(int i=0; i < gerAlocacoes.getListaDeSalas().size(); i++){
            modeloSala.add(i, salaFormatada(salas.get(i)));
        }
        jList_Salas.updateUI();
    }

    private void atualizarEventos(){
        modeloEvento = new DefaultListModel();
        jList_Eventos.setModel(modeloEvento);

        for(int i=0; i < eventos.size(); i++){

            if (eventos.get(i).estaAlocado())
                modeloEvento.add(i, "*" + eventoFormatado(eventos.get(i)));
            else
                modeloEvento.add(i, eventoFormatado(eventos.get(i)));
        }
        jList_Eventos.updateUI();
    }
//=============================================================================

    // Metodo com objetivo de converter Alocaveis para Sala
    private void atualizaSalasDoGerenciador(){
        int numSalas = gerAlocacoes.getListaDeSalas().size();

        salas = new ArrayList<Sala>();
        
        Sala salaAtual = null;
        for(int i=0; i < numSalas; i++){
            salaAtual = (Sala) gerAlocacoes.getListaDeSalas().get(i);
            salas.add(salaAtual);
        }
    }

    // Metodo com objetivo de converter Escalonaveis para Evento
    private void atualizaEventosDoGerenciador(){
        int numEventos = gerAlocacoes.getListaDeEventos().size();

        eventos = new ArrayList<Evento>();
        Evento eventoAtual = null;
        for(int i=0; i < numEventos; i++){
            eventoAtual = (Evento) gerAlocacoes.getListaDeEventos().get(i);
            eventos.add(eventoAtual);
        }
    }
    
    private void atualizaModelos(){
        modeloSala = new DefaultListModel();
        modeloEvento = new DefaultListModel();
        jList_Salas.setModel(modeloSala);
        jList_Eventos.setModel(modeloEvento);
    }

    private void atualizaDados(){
        final int ZERO_EVENTO_ALOCADO = 0;
        int contadorSalasAlocadas = 0;
        int contadorEventosAlocados = 0;

        jLabel_SalasExistentes.setText(
                gerAlocacoes.getListaDeSalas().size() + "");

        for (int i=0; i < salas.size(); i++){
            if ( salas.get(i).getEventos().size() > ZERO_EVENTO_ALOCADO)
                contadorSalasAlocadas++;
        }
        jLabel_SalasAlocadas.setText(contadorSalasAlocadas + "");

        jLabel_EventosExistentes.setText(
                gerAlocacoes.getListaDeEventos().size() + "");

        for (int i=0; i < eventos.size(); i++){
            if (eventos.get(i).estaAlocado())
                contadorEventosAlocados++;
        }
        jLabel_EventosAlocados.setText(contadorEventosAlocados + "");
    }
    
    //Metodos relacionados a formatacao das entidades dentro da jList

    private String eventoFormatado(Evento evento){
        String saida = "";

        saida = evento.getId() + " - " +
                evento.getArea() + " - " +
                evento.getContato() + " - " +
                evento.getNome() + " - Inicio: " +
                evento.getInicio() + " - Fim: " +
                evento.getFim();
        
        return saida;
    }

    private String salaFormatada(Sala sala){
        String saida = "";

        saida =  sala.getId() + " - " +
                 sala.getFinalidade() + " - " +
                 sala.getTipo() + " - " + sala.getApelido();

        return saida;
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GerenciadorAlocacao().setVisible(true);
            }
        });
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_Alocar;
    private javax.swing.JButton jButton_Desalocar;
    private javax.swing.JButton jButton_Voltar;
    private javax.swing.JButton jButton_ZerarSistema;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel_Eventos;
    private javax.swing.JLabel jLabel_EventosAlocados;
    private javax.swing.JLabel jLabel_EventosExistentes;
    private javax.swing.JLabel jLabel_Msg_EvAtual;
    private javax.swing.JLabel jLabel_Salas;
    private javax.swing.JLabel jLabel_SalasAlocadas;
    private javax.swing.JLabel jLabel_SalasExistentes;
    private javax.swing.JList jList_Eventos;
    private javax.swing.JList jList_Salas;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel_Eventos;
    private javax.swing.JPanel jPanel_Salas;
    private javax.swing.JPanel jPanel_VerificaDados;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    // End of variables declaration//GEN-END:variables

}
